Home:ALL Converter>How to build Boost with static ICU via MinGW on Linux for Windows

How to build Boost with static ICU via MinGW on Linux for Windows

Ask Time:2020-02-02T09:09:59         Author:Benjamin Buch

Json Formatter

I want to build the C++ Boost libraries with MinGW for Windows in a Docker Linux image. For libz, bz2, xz, zstd and ICU this already worked and the corresponding files are installed. Everything is statically linked.

The file system structure looks like this:

$ ls -l /mingw/
drwxr-xr-x 1 root root 4096 Feb  2 00:09 include
drwxr-xr-x 1 root root 4096 Feb  2 00:09 lib
drwxr-xr-x 5 root root 4096 Feb  2 00:09 share
$ ls -l /mingw/lib/
drwxr-xr-x 3 root root     4096 Feb  2 00:09 icu
-rw-r--r-- 1 root root   371114 Feb  1 19:58 libbz2.a
-rw-r--r-- 1 root root  1940512 Feb  2 00:03 liblzma.a
-rwxr-xr-x 1 root root      876 Feb  2 00:03 liblzma.la
-rwxr-xr-x 1 root root      736 Feb  2 00:09 libsicudt.a
-rwxr-xr-x 1 root root 10895028 Feb  2 00:09 libsicuin.a
-rwxr-xr-x 1 root root   143990 Feb  2 00:09 libsicuio.a
-rwxr-xr-x 1 root root  5196448 Feb  2 00:09 libsicuuc.a
-rw-r--r-- 1 root root   118758 Feb  1 18:15 libz.a
-rw-r--r-- 1 root root   850738 Feb  1 21:11 libzstd.a
drwxr-xr-x 1 root root     4096 Feb  2 00:09 pkgconfig
$ ls -l /mingw/include/
-rw-r--r-- 1 root root   6240 Feb  1 19:58 bzlib.h
-rw-r--r-- 1 root root   4569 Nov  4 17:54 cover.h
drwxr-xr-x 2 root root   4096 Feb  2 00:03 lzma
-rw-r--r-- 1 root root   9817 Feb  2 00:03 lzma.h
drwxr-xr-x 2 root root   4096 Feb  2 00:09 unicode
-rw-r--r-- 1 root root  11500 Nov  4 17:54 zbuff.h
-rw-rw-r-- 1 root root  16298 Jan 15  2017 zconf.h
-rw-r--r-- 1 root root  17203 Nov  4 17:54 zdict.h
-rw-rw-r-- 1 root root  96239 Jan 15  2017 zlib.h
-rw-r--r-- 1 root root 119972 Nov  4 17:54 zstd.h
-rw-r--r-- 1 root root   3751 Nov  4 17:54 zstd_errors.h

I also created a site-config.jam file thanks to which b2 finds libz, bz2, xz and zstd.

$ more /etc/site-config.jam 
using gcc : : x86_64-w64-mingw32-g++ : 
    <cxxflags>-DBOOST_ASIO_HAS_STD_STRING_VIEW
    <cxxflags>-DBOOST_ASIO_HAS_STD_IOSTREAM_MOVE
    <cxxflags>--sysroot=/mingw
    <cxxflags>-std=c++17 ;
using zlib : : <include>/mingw/include <search>/mingw/lib ;
using bzip2 : : <include>/mingw/include <search>/mingw/lib ;
using lzma : : <include>/mingw/include <search>/mingw/lib ;
using zstd : : <include>/mingw/include <search>/mingw/lib ;

Unfortunately this is not possible for ICU. Using -sICU_PATH did not work either.

My current command line to build is:

$ cd /mnt/boost_1_72_0
$ ./b2 toolset=gcc variant=release threading=multi link=static \
  target-os=windows architecture=x86 address-model=64 abi=ms binary-format=pe \
  -sICU_PATH=/mingw/lib \
  --layout=system --prefix=/install \
  --without-python --without-graph_parallel --without-mpi \
  -j $(nproc) install

This prints:

Performing configuration checks

    - default address-model    : 64-bit
    - default architecture     : x86
    - C++11 mutex              : yes
[...]
    - has_icu builds           : no
    - zlib                     : yes
    - bzip2                    : yes
    - lzma                     : yes
    - zstd                     : yes
    - lzma                     : yes
    - has_lzma_cputhreads builds : yes
    - iconv (libc)             : no
    - iconv (separate)         : no
    - icu                      : no
    - icu (lib64)              : no
    - native-atomic-int32-supported : yes
    - message-compiler         : no
    - native-syslog-supported  : no
    - pthread-supports-robust-mutexes : no
    - compiler-supports-ssse3  : yes
    - compiler-supports-avx2   : yes
    - gcc visibility           : yes
    - long double support      : yes
    - libbacktrace builds      : no
    - addr2line builds         : no
    - WinDbg builds            : no
    - WinDbgCached builds      : no
    - BOOST_COMP_GNUC >= 4.3.0 : yes
[...]

You can run and reproduce this by my test Docker image:

$ docker run -it --rm bebuch/boost-with-static-icu-prepared:latest

What do I have to change to make icu switch to yes in the b2 run?

Edit 2020-02-03: Part of the answer is a bug that was fixed in Boost 1.73.0:

Author:Benjamin Buch,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60022476/how-to-build-boost-with-static-icu-via-mingw-on-linux-for-windows
yy